package com.test.dao.impl;

import com.test.dao.IHouseDao;
import com.test.model.House;
import com.test.model.HouseMeter;
import com.test.model.HouseMeterCurrentData;
import com.test.model.HouseValve;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

/**
 * Created by ZZF on 2017/7/17.
 */
@Repository
public class HouseDaoImpl extends BaseDaoImpl<House> implements IHouseDao {

    @Override
    public HouseMeter findHouseMeter(int houseId) {

        String Sql = "SELECT b.* FROM g_house a INNER JOIN rcc_e_housemeter b ON b.houseId=a.uniqueId " +
                "WHERE a.uniqueId=" + houseId;

        Query query = getSession().createSQLQuery(Sql).addEntity(HouseMeter.class);

        return (HouseMeter)query.uniqueResult();
    }

    @Override
    public HouseValve findHouseValve(int houseId) {
        String Sql = "SELECT b.* FROM g_house a INNER JOIN rcc_e_housevalve b ON b.houseId=a.uniqueId " +
                "WHERE a.uniqueId=" + houseId;
        Query query = getSession().createSQLQuery(Sql).addEntity(HouseValve.class);

        return (HouseValve) query.uniqueResult();
    }

    @Override
    public HouseMeterCurrentData findMeterCurrent(int houseId) {
        String sql="SELECT a.* FROM rcc_d_housemetercurrentdata a INNER JOIN rcc_e_housemeter b ON a.houseMeterId= b.uniqueId INNER JOIN g_house c ON" +
                " c.uniqueId=b.houseId WHERE c.uniqueId="+houseId;

        Query query = getSession().createSQLQuery(sql).addEntity(HouseMeterCurrentData.class);

        return (HouseMeterCurrentData)query.uniqueResult();
    }
}
